<?php

use App\Http\ApiControllers\AuthController;
use App\Http\ApiControllers\CommentController;
use App\Http\ApiControllers\GiftController;
use App\Http\ApiControllers\GuardianController;
use App\Http\ApiControllers\LikeController;
use App\Http\ApiControllers\NotifyController;
use App\Http\ApiControllers\PlayerController;
use App\Http\ApiControllers\StatementController;
use App\Http\ApiControllers\SupportController;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

# region 选手接口
Route::get('players/{player}', [PlayerController::class, 'index']);
Route::get('players/{player}/info', [PlayerController::class, 'info']);

# 如果前端是401，获取登录地址
Route::post('auth/{player}', [AuthController::class, 'auth']);
Route::get('captcha/{player}', [AuthController::class, 'captcha']);

Route::group([
    'middleware' => 'auth:sanctum',
], function (Router $router) {
    # 点赞
    $router->post('players/{player}/likes', [LikeController::class, 'store']);
    # 提交评论
    $router->post('players/{player}/comments', [CommentController::class, 'store']);
    $router->post('players/{player}/supports', [SupportController::class, 'store']);
    $router->post('players/{player}/gifts/{gift}', [GiftController::class, 'store']);
    # 手机监控中心
    $router->get('statement', [StatementController::class, 'index']);
    # 家长控制中心
    $router->get('guardian', [GuardianController::class, 'index']);
});

Route::group([
], function (Router $router) {
    $router->get('players/{player}/share', [PlayerController::class, 'share']);
    $router->get('players/{player}/likes', [LikeController::class, 'index'])
        ->name('likes.index');
    $router->get('players/{player}/comments', [CommentController::class, 'index'])
        ->name('comments.index');
    $router->get('players/{player}/supports', [SupportController::class, 'index']);
    $router->get('players/{player}/gifts', [GiftController::class, 'index']);
});

/**
 * 支付，退款结果通知接口
 */
Route::post('notify/payment/{appKey}', [NotifyController::class, 'payment'])
    ->name('notify.payment');
Route::post('notify/refund/{appKey}', [NotifyController::class, 'refund'])
    ->name('notify.refund');

Route::fallback(function () {
    request()->headers->set('Accept', 'application/json');
    throw new NotFoundHttpException();
});
